package com.yzh.openai.handler;

import com.yzh.openai.types.common.Constants;
import com.yzh.openai.types.common.Response;
import com.yzh.openai.types.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public Response<?> runtimeExceptionHandler(RuntimeException e) {
        log.error("runtimeException", e);
        return Response.error(Constants.ResponseCode.SYSTEM_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public Response<?> chatExceptionHandler(BusinessException e) {
        log.error("chatException", e);
        return Response.error(e.getCode(), e.getMessage());
    }
}
